#include "sound.h"

void loadSong( char filename[200] )
{
 if ( jeu.musique != NULL )
 {
    Mix_HaltMusic();
    Mix_FreeMusic(jeu.musique);
 }
 jeu.musique = Mix_LoadMUS( filename );
 if (jeu.musique == NULL)
    {
        fprintf(stderr, "Can't read the music \n");
        exit(1);
    }
     if(Mix_PlayMusic(jeu.musique, -1)==-1)
     {
        printf("Mix_PlayMusic: %s\n", Mix_GetError());
     }

}
void loadSound(void)
{
   jeu.destroy_sound = Mix_LoadWAV("destroy.wav");
   if (jeu.destroy_sound == NULL)
    {
        fprintf(stderr, "Can't read the destroy sound FX \n");
        exit(1);
    }

   jeu.jump_sound = Mix_LoadWAV("jump.wav");
   if (jeu.jump_sound == NULL)
    {
        fprintf(stderr, "Can't read the jump sound FX \n");
        exit(1);
    }

}
         
void playSoundFx(int type)
{

    switch (type)
    {
 
        case DESTROY:
            Mix_PlayChannel(-1, jeu.destroy_sound, 0);
        break;

        case JUMp :
            Mix_PlayChannel(-1, jeu.jump_sound, 0);
        break;   

   }

}
         

void freeSound(void)
{

   Mix_FreeChunk(jeu.destroy_sound);
   Mix_FreeChunk(jeu.jump_sound);
 
}
